package com.yuju.log.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.yuju.common.Result;
import com.yuju.log.service.BaseLogService;
import com.yuju.log.service.IAccountLogService;
import com.yuju.log.service.IOrderLogService;
import com.yuju.log.service.IPriceSchemeLogService;
import com.yuju.log.service.IRoomLogService;

/**
 * 
 * 类名：LogServiceImpl  <br />
 *
 * 功能：日志服务
 *
 * @author : xuehj <br />
 * @Date : 2017年12月28日 下午2:08:28  <br />
 * @version : 1.1 <br />
 */
@Service
public class LogServiceImpl extends BaseLogService {
	
	@Autowired
	private IAccountLogService accountLogService;
	
	@Autowired
	private IOrderLogService orderLogService;
	
	@Autowired
	private IRoomLogService roomLogService;
	
	@Autowired
	private IPriceSchemeLogService priceSchemeLogService;
	
	@Override
	public void before(String path, JSONObject obj) {
		boolean flag = false;
		// 预订、入住、退房、订单异动、离店日志
		if (path.startsWith("/roomOrder") || path.startsWith("/reserve/")) {
			flag = true;
			orderLogService.before(path, obj);
		}
		
		// 账务日志：订单账务、单位账务
		if (path.startsWith("/settle") || path.startsWith("/reserveAccount") || path.startsWith("/unitAccountBook")
				|| path.startsWith("/unitAccount") || path.startsWith("/orderAccount")) {
			flag = true;
			accountLogService.before(path, obj);
		}
		
		// 房间日志
		if (path.startsWith("/room") || path.startsWith("/orderAccount") || path.startsWith("/roomRepair") || path.startsWith("/roomOrder") ) {
			flag = true;
			roomLogService.before(path, obj);
		}
		//价格方案日志
		if (path.startsWith("/priceScheme/update")) {
			flag = true;
			priceSchemeLogService.before(path, obj);
		}
		if (!flag) {
			log(path, obj);
		}
	}

	@Override
	public void handle(String path, JSONObject obj, Result ret) {
		boolean flag = false;
		// 预订、入住、退房、订单异动、离店日志
		if (path.startsWith("/roomOrder") || path.startsWith("/reserve/")) {
			flag = true;
			orderLogService.log(path, obj, ret);
		}
		
		// 账务日志：订单账务、单位账务
		if (path.startsWith("/settle") || path.startsWith("/reserveAccount") || path.startsWith("/unitAccountBook")
				|| path.startsWith("/unitAccount") || path.startsWith("/orderAccount")) {
			flag = true;
			accountLogService.log(path, obj, ret);
		}
		
		// 房间日志
		if (path.startsWith("/room") || path.startsWith("/orderAccount") || path.startsWith("/roomRepair") || path.startsWith("/roomOrder") ) {
			flag = true;
			roomLogService.log(path, obj, ret);
		}
		
		// 价格方案日志
		if (path.startsWith("/priceScheme")) {
			priceSchemeLogService.log(path, obj, ret);
		}
		
		if (!flag) {
			log(path, obj);
		}
	}

}
